define(["jquery","bbcare"],function($,$bb){
    var URL = $bb.baseUrl("nutrition");
    var servers = {};

    /**
     * 查询疗程库
     */
    servers.ajaxCourseLibirayList = function(callback){
        $bb.ajax({
            url: URL + "nutritiouScheme/service/nutrition/courselibiray/list",
            success: function(data){
                if(data.success){
                    callback(data.rows);
                }else{
                    $bb.toastShow(data.msg ? data.msg : "查询疗程库出错！");
                }
            }
        });
    };

    /**
     * 处理疗程库数据
     */
    servers.handleCourseLibirayList = function(list){
        for (var i = 0; i < list.length; i++) {
            list[i].createTime = list[i].createTime.substr(0,10);
        }
        return {"list":list}
    }

    /**
     * 获取当前需要修改的疗程库的原本数据
     */
    servers.getSetCourseLibraryOriginalData = function(data,libraryId){
        for (var i = 0; i < data.length; i++) {
            if( data[i].libraryId == libraryId ) {
                return data[i];
            }
        }
    }

    /**
     * 添加/修改疗程库
     */
    servers.ajaxCourseLibirayModify = function(params,callback,className){
        $bb.ajax({
            url: URL + "nutritiouScheme/service/nutrition/courselibiray/modify",
            data: JSON.stringify({
                data: params
            }),
            success: function(data){
                if(data.success){
                    callback(data.data,params.libraryId,className);
                }else{
                    $bb.toastShow(data.msg ? data.msg : "添加或修改疗程库出错！");
                }
            }
        });
    }

    return servers;
});
